<!DOCTYPE html>
<html class="loading" lang="en" data-textdirection="ltr">
  <!-- BEGIN: Head-->
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
    <title>权益管理 - 生态圈后台</title>
    <link rel="icon" th:href="@{/images/favicon.ico}" th:mce_href="@{/images/favicon.ico}" type="image/x-icon">
    <link rel="shortcut icon" th:href="@{/images/favicon.ico}" th:mce_href="@{/images/favicon.ico}" type="image/x-icon">
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="app-assets/vendors/vendors.min.css" th:href="@{/app-assets/vendors/vendors.min.css}">
    <link rel="stylesheet" type="text/css" href="app-assets/vendors/data-tables/css/jquery.dataTables.min.css" th:href="@{/app-assets/vendors/data-tables/css/jquery.dataTables.min.css}">
    <link rel="stylesheet" type="text/css" href="app-assets/css/themes/vertical-gradient-menu-template/materialize.css" th:href="@{/app-assets/css/themes/vertical-gradient-menu-template/materialize.css}">
    <link rel="stylesheet" type="text/css" href="app-assets/css/themes/vertical-gradient-menu-template/style.css" th:href="@{/app-assets/css/themes/vertical-gradient-menu-template/style.css}">
    <link rel="stylesheet" type="text/css" href="app-assets/css/custom/custom.css" th:href="@{/app-assets/css/custom/custom.css}">
    <link rel="stylesheet" type="text/css" href="app-assets/css/pages/dashboard.css" th:href="@{/app-assets/css/pages/dashboard.css}">
    <link rel="stylesheet" type="text/css" href="app-assets/css/pages/data-tables.css" th:href="@{/app-assets/css/pages/data-tables.css}">
  </head>
  <!-- END: Head-->
  <body class="vertical-layout page-header-light vertical-menu-collapsible vertical-gradient-menu 2-columns app-page" data-open="click" data-menu="vertical-gradient-menu" data-col="2-columns">

    <header class="page-topbar" id="header">
      <div class="navbar navbar-fixed">
        <nav class="navbar-main navbar-color nav-collapsible sideNav-lock navbar-light">
          <div class="nav-wrapper">
            <ul class="navbar-list right">
              <li><a class="waves-effect waves-block waves-light profile-button" href="javascript:void(0);" data-target="profile-dropdown"><span sec:authentication="name">admin</span></a></li>
            </ul>
            <ul class="dropdown-content" id="profile-dropdown">
              <li><a class="grey-text text-darken-1" href="user-lock-screen.html"><i class="material-icons">vpn_key</i> 修改密码</a></li>
              <li><a class="grey-text text-darken-1" href="user-login.html"><i class="material-icons">keyboard_tab</i> 退出登录</a></li>
            </ul>
          </div>
        </nav>
      </div>
    </header>

    <!-- BEGIN: SideNav-->
    <aside class="sidenav-main nav-expanded nav-lock nav-collapsible sidenav-light sidenav-active-square">
      <div class="brand-sidebar">
        <h1 class="logo-wrapper brand-logo darken-1"><span class="logo-text hide-on-med-and-down">生态圈后台</span></h1>
      </div>
      <ul class="sidenav sidenav-collapsible leftside-navigation collapsible sidenav-fixed menu-shadow" id="slide-out" data-menu="menu-navigation" data-collapsible="menu-accordion">
        <li class="navigation-header"><a class="navigation-header-text">功能</a><i class="navigation-header-icon material-icons">more_horiz</i>
        </li>
        <li class="bold"><a class="waves-effect waves-cyan " href="app-email.html"><i class="material-icons">mail_outline</i><span class="menu-title" data-i18n="">信托客户</span></a>
        </li>
        <li class="bold"><a class="waves-effect waves-cyan " href="app-email.html"><i class="material-icons">mail_outline</i><span class="menu-title" data-i18n="">企业</span></a>
        </li>
        <li class="active bold"><a class="waves-effect waves-cyan active " href="app-email.html"><i class="material-icons">mail_outline</i><span class="menu-title" data-i18n="">权益</span></a>
        </li>
        <!-- <li class="active bold"><a class="waves-effect waves-cyan active " href="app-email.html"><i class="material-icons">mail_outline</i><span class="menu-title" data-i18n="">选中</span></a>
        </li> -->
        <li class="bold"><a class="collapsible-header waves-effect waves-cyan " href="#"><i class="material-icons">settings_input_svideo</i><span class="menu-title" data-i18n="">优惠券</span></a>
          <div class="collapsible-body">
            <ul class="collapsible collapsible-sub" data-collapsible="accordion">
              <!-- <li class="active"><a class="collapsible-body active" href="dashboard-modern.html" data-i18n=""><i class="material-icons">radio_button_unchecked</i><span>选中</span></a>
              </li> -->
              <li><a class="collapsible-body" href="dashboard-modern.html" data-i18n=""><i class="material-icons">radio_button_unchecked</i><span>优惠券池</span></a>
              </li>
              <li><a class="collapsible-body" href="dashboard-ecommerce.html" data-i18n=""><i class="material-icons">radio_button_unchecked</i><span>已发放优惠券</span></a>
              </li>
              <li><a class="collapsible-body" href="dashboard-analytics.html" data-i18n=""><i class="material-icons">radio_button_unchecked</i><span>已领取优惠券</span></a>
              </li>
              <li><a class="collapsible-body" href="dashboard-modern.html" data-i18n=""><i class="material-icons">radio_button_unchecked</i><span>已使用优惠券</span></a>
              </li>
              <li><a class="collapsible-body" href="dashboard-modern.html" data-i18n=""><i class="material-icons">radio_button_unchecked</i><span>已结算优惠券</span></a>
              </li>
              <li><a class="collapsible-body" href="dashboard-modern.html" data-i18n=""><i class="material-icons">radio_button_unchecked</i><span>按客户等级发放</span></a>
              </li>
              <li><a class="collapsible-body" href="dashboard-modern.html" data-i18n=""><i class="material-icons">radio_button_unchecked</i><span>按客户发放</span></a>
              </li>
            </ul>
          </div>
        </li>
        <li class="bold"><a class="waves-effect waves-cyan " href="app-email.html"><i class="material-icons">mail_outline</i><span class="menu-title" data-i18n="">对账</span></a>
        </li>
        <li class="bold"><a class="waves-effect waves-cyan " href="app-email.html"><i class="material-icons">mail_outline</i><span class="menu-title" data-i18n="">结算</span></a>
        </li>
        <li class="navigation-header"><a class="navigation-header-text">系统</a><i class="navigation-header-icon material-icons">more_horiz</i>
        </li>
        <li class="bold"><a class="waves-effect waves-cyan " href="app-email.html"><i class="material-icons">mail_outline</i><span class="menu-title" data-i18n="">帐号管理</span></a>
        </li>
        <li class="bold"><a class="waves-effect waves-cyan " href="app-email.html"><i class="material-icons">mail_outline</i><span class="menu-title" data-i18n="">操作日志</span></a>
        </li>
        <li><span class="menu-title" data-i18n="">&nbsp</span>
        </li>
        <li><span class="menu-title" data-i18n="">&nbsp</span>
        </li>
      </ul>
      <div class="navigation-background"></div><a class="sidenav-trigger btn-sidenav-toggle btn-floating btn-medium waves-effect waves-light hide-on-large-only" href="#" data-target="slide-out"><i class="material-icons">menu</i></a>
    </aside>
    <!-- END: SideNav-->

    <!-- BEGIN: Page Main-->
    <div id="main">
      <div class="row">

<!-- BEGIN: Content -->
<div class="col s12">
  <div id="button-trigger" class="card card card-default scrollspy">
    <div class="card-content">
      <h5 class="card-title">权益管理</h5>
      <div class="row">
        <div class="col s12">
          <form id="search">
            <div class="row">
              <div class="input-field col s12 input-field-compact">
              <div class="input-field col s2 input-field-compact">
                <input type="text" name="title" id="title_s" th:value="${search.title}" />
                <label for="title_s">名称</label>
              </div>
              <div class="input-field col s4 input-field-compact">
                <select name="companyId">
                <option value="" selected>所属企业</option>
                <option th:each="c : ${companies}" th:value="${c.id}"  th:text="${c.name}" th:selected="${c.id} == ${search.company.id}">企业1</option>
                </select>
              </div>
              <div class="input-field col s1 input-field-compact">
                <div class="input-field col s1 input-field-compact">
                  <a th:href="'javascript:search();'" class="waves-effect waves-light btn-floating search-btn btn-small"><i class="material-icons right">search</i></a>
                </div>
              </div>
              </div>
            </div>
          </form>
        </div>

        <div class="input-field col s12 right input-field-compact">
          <div class="input-field col s1 right input-field-compact">
            <a class="waves-effect waves-light btn-floating btn-small blue right modal-trigger" href="#modal2"><i class="large material-icons">add</i></a>
          </div>
        </div>

        <div class="col s12">
          <table>
            <thead>
              <tr>
                <th width="5%">ID</th>
                <th width="20%">名称</th>
                <th width="20%">所属企业</th>
                <th width="10%">结算单价</th>
                <th width="10%">开始日期</th>
                <th width="10%">结束日期</th>
                <th width="10%">备注</th>
                <th width="15%">操作</th>
              </tr>
            </thead>
            <tbody>
              <tr th:each="a : ${activities}">
                <td th:text="${a.id}" th:title="${a.id}">1</td>
                <td th:text="${a.title}" th:title="${a.title}">中秋大闸蟹</td>
                <td th:text="${a.company.name}" th:title="${a.company.name}"></td>
                <td th:text="${#numbers.formatCurrency(a.price)}" th:title="${#numbers.formatCurrency(a.price)}">4/3/2</td>
                <td th:text="${a.startDate}" th:title="${a.startDate}">2018-09-30</td>
                <td th:text="${a.endDate}" th:title="${a.endDate}">正常</td>
                <td th:text="${a.remark}" th:title="${a.remark}">备注</td>
                <td class="no-padding">
                  <a th:href="'javascript:openEditModal(\''+${a.id}+'\');'" title="编辑"><i class="material-icons">edit</i></a>
                  <a th:href="'javascript:deleteSubmit(\''+${a.id}+'\');'" title="删除"><i class="material-icons">delete</i></a>
                </td>
              </tr>
            </tbody>
          </table>
          <div class="dataTables_info" id="data-table-row-grouping_info" role="status" aria-live="polite">Showing 1 to 25 of 57 entries</div>
          <div>
	  	  <ul class="pagination" th:if="${activities.totalPages} > 0"></ul>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<!-- END: Content -->

      </div>
    </div>
    <!-- END: Page Main-->

    <!-- BEGIN: Modal -->
  <div id="modal1" class="modal modal-fixed-footer">
    <div class="modal-header">
      <h6>编辑权益</h6>
      <a class="btn-flat modal-close"><i class="material-icons">close</i></a>
    </div>
    <div class="modal-content" style="border: unset; border-radius: 0;">
      <div class="row">
        <form class="col s12">
          <input name="id" type="hidden">
          <div class="row">
            <div class="col s12 input-field compact">
              <input type="text" name="title" id="title1" class="validate" required maxlength="50">
              <label for="title1"><font color="red">*</font>名称</label>
              <span class="helper-text" data-error="必填项" data-success="right"></span>
            </div>
          </div>
          <div class="row">
            <div class="col s12 input-field compact">
              <textarea id="content1" name="content" class="materialize-textarea validate" maxlength="400"></textarea>
              <label for="content1">介绍</label>
              <span class="helper-text" data-error="wrong" data-success="right"></span>
            </div>
          </div>
          <div class="row">
            <div class="col s12 input-field compact">
              <select name="companyId">
                <option value="" disabled selected>请选择所属企业</option>
                <option th:each="c : ${companies}" th:value="${c.id}"  th:text="${c.name}">企业1</option>
              </select>
              <label><font color="red">*</font>所属企业</label>
              <span class="helper-text" data-error="必选项" data-success="right"></span>
            </div>
          </div>
          <div class="row">
            <div class="col s12 input-field compact">
              <textarea name="scope" id="scope1" class="validate materialize-textarea" required maxlength="400"></textarea>
              <label for="scope1"><font color="red">*</font>参与范围</label>
              <span class="helper-text" data-error="必填项" data-success="right"></span>
            </div>
          </div>
          <div class="row">
             <div class="col s6 input-field compact">
              <input type="text" name="startDate" id="startDate1" class="date-picker validate" required>
              <label for="startDate1"><font color="red">*</font>开始日期</label>
              <span class="helper-text" data-error="必填项，不能晚于结束日期" data-success="right"></span>
            </div>
            <div class="col s6 input-field compact">
              <input type="text" name="endDate" id="endDate1" class="date-picker validate" required>
              <label for="endDate1"><font color="red">*</font>结束日期</label>
              <span class="helper-text" data-error="必填项，不能早于开始日期" data-success="right"></span>
            </div>
          </div>
          <div class="row">
            <div class="col s12 input-field compact">
              <input type="number" name="price" step="0.01" id="price1" class="validate" required min="0.01">
              <label for="price1"><font color="red">*</font>结算单价（元）</label>
              <span class="helper-text" data-error="必填项" data-success="right"></span>
            </div>
          </div>
          <div class="row">
            <div class="col s12 input-field compact">
              <textarea name="remark" id="remark1" class="validate materialize-textarea" maxlength="400"></textarea>
              <label for="remark1">备注</label>
            </div>
          </div>
          <input type="reset" style="display:none;" />
        </form>
      </div>
    </div>
    <div class="modal-footer">
      <a href="#!" class="modal-close waves-effect waves-light btn-flat" style="margin-right: 10px;">取消</a>
      <button class="btn waves-effect waves-light light-blue darken-1" type="submit" name="action" style="margin-right: 10px;" onclick="editSubmit()">确认</button>
    </div>
  </div>

  <div id="modal2" class="modal modal-fixed-footer">
    <div class="modal-header">
      <h6>新增权益</h6>
      <a class="btn-flat modal-close"><i class="material-icons">close</i></a>
    </div>
    <div class="modal-content" style="border: unset; border-radius: 0;">
      <div class="row">
        <form class="col s12">
          <div class="row">
            <div class="col s12 input-field compact">
              <input type="text" name="title" id="title" class="validate" required maxlength="50">
              <label for="title"><font color="red">*</font>名称</label>
              <span class="helper-text" data-error="必填项" data-success="right"></span>
            </div>
          </div>
          <div class="row">
            <div class="col s12 input-field compact">
              <textarea id="content" name="content" class="materialize-textarea validate" maxlength="400"></textarea>
              <label for="content">介绍</label>
              <span class="helper-text" data-error="wrong" data-success="right"></span>
            </div>
          </div>
          <div class="row">
            <div class="col s12 input-field compact">
              <select name="companyId">
                <option value="" disabled selected>请选择所属企业</option>
                <option th:each="c : ${companies}" th:value="${c.id}"  th:text="${c.name}">企业1</option>
              </select>
              <label><font color="red">*</font>所属企业</label>
              <span class="helper-text" data-error="必选项" data-success="right"></span>
            </div>
          </div>
          <div class="row">
            <div class="col s12 input-field compact">
              <textarea name="scope" id="scope" class="validate materialize-textarea" required maxlength="400"></textarea>
              <label for="scope"><font color="red">*</font>参与范围</label>
              <span class="helper-text" data-error="必填项" data-success="right"></span>
            </div>
          </div>
          <div class="row">
           <div class="col s6 input-field compact">
             <input type="text" name="startDate" id="startDate" class="date-picker validate" required>
             <label for="startDate"><font color="red">*</font>开始日期</label>
             <span class="helper-text" data-error="必填项，不能晚于结束日期" data-success="right"></span>
           </div>
           <div class="col s6 input-field compact">
              <input type="text" name="endDate" id="endDate" class="date-picker validate" required>
              <label for="endDate"><font color="red">*</font>结束日期</label>
              <span class="helper-text" data-error="必填项，不能早于开始日期" data-success="right"></span>
            </div>
          </div>
          <div class="row">
            <div class="col s12 input-field compact">
              <input type="number" name="price" step="0.01" id="price" class="validate" required min="0.01">
              <label for="price"><font color="red">*</font>结算单价（元）</label>
              <span class="helper-text" data-error="必填项" data-success="right"></span>
            </div>
          </div>
          <div class="row">
            <div class="col s12 input-field compact">
              <textarea name="remark" id="remark" class="validate materialize-textarea" maxlength="400"></textarea>
              <label for="remark">备注</label>
            </div>
          </div>
          <input type="reset" style="display:none;" />
        </form>
      </div>
    </div>
    <div class="modal-footer">
      <a href="#!" class="modal-close waves-effect waves-light btn-flat" style="margin-right: 10px;">取消</a>
      <button class="btn waves-effect waves-light light-blue darken-1" type="submit" name="action" style="margin-right: 10px;" onclick="addSubmit()">确认</button>
    </div>
  </div>

  <div id="modal3" class="modal modal-fixed-footer">
    <div class="modal-header">
      <h6>修改密码</h6>
      <a class="btn-flat modal-close"><i class="material-icons">close</i></a>
    </div>
    <div class="modal-content" style="border: unset; border-radius: 0;">
      <div class="row">
        <form class="col s12">
          <div class="row">
            <div class="col s8 input-field">
              <input type="password" name="oldPassword" id="oldPassword" class="validate" required>
              <label for="oldPassword"><font color="red">*</font>原密码</label>
              <span class="helper-text" data-error="wrong" data-success="right"></span>
            </div>
          </div>
          <div class="row">
            <div class="col s12 input-field">
              <input type="password" name="newPassword" id="newPassword" class="validate" required>
              <label for="newPassword"><font color="red">*</font>新密码</label>
              <span class="helper-text" data-error="wrong" data-success="right"></span>
            </div>
          </div>
          <div class="row">
            <div class="col s12 input-field">
              <input type="password" name="confirmPassword" id="confirmPassword" class="validate" required>
              <label for="confirmPassword"><font color="red">*</font>确认密码</label>
              <span class="helper-text" data-error="wrong" data-success="right"></span>
            </div>
          </div>
          <input type="reset" style="display:none;" />
        </form>
      </div>
    </div>
    <div class="modal-footer">
      <a href="#!" class="modal-close waves-effect waves-light btn-flat" style="margin-right: 10px;">取消</a>
      <button class="btn waves-effect waves-light light-blue darken-1" type="submit" name="action" style="margin-right: 10px;" th:onclick="'updatePwdSubmit('+${#authentication.principal.id}+')'">确认</button>
    </div>
  </div>

    <!-- END: Modal -->

    <!-- BEGIN: Footer-->

    <footer class="page-footer footer footer-static footer-light navbar-border navbar-shadow">
      <div class="footer-copyright">
        <div class="container"><span>&copy; 2019 Shandong Yumo. All rights reserved.</span></div>
      </div>
    </footer>

    <!-- END: Footer-->

    <script src="js/jquery-3.3.1.min.js" th:src="@{/js/jquery-3.3.1.min.js}"></script>
    <script src="js/materialize.js" th:src="@{/js/materialize.js}"></script>
    <script src="plugins/perfect-scrollbar/perfect-scrollbar.min.js" th:src="@{/plugins/perfect-scrollbar/perfect-scrollbar.min.js}"></script>
    <script src="plugins/bootstrap-datepicker/js/bootstrap-datepicker.min.js" th:src="@{/plugins/bootstrap-datepicker/js/bootstrap-datepicker.min.js}"></script>
    <script src="plugins/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js" th:src="@{/plugins/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js}" charset="UTF-8"></script>
    <script src="plugins/bootstrap-sweetalert/sweetalert.min.js" th:src="@{/plugins/bootstrap-sweetalert/sweetalert.min.js}"></script>
    <script src="js/common.js" th:src="@{/js/common.js}"></script>
    <script src="js/jquery.page.js" th:src="@{/js/jquery.page.js}"></script>
    <script src="app-assets/js/vendors.min.js" type="text/javascript" th:src="@{/app-assets/js/vendors.min.js}"></script>
    <script src="app-assets/vendors/chartjs/chart.min.js" type="text/javascript" th:src="@{/app-assets/vendors/chartjs/chart.min.js}"></script>
    <script src="app-assets/js/plugins.js" type="text/javascript" th:src="@{/app-assets/js/plugins.js}"></script>
    <script src="app-assets/js/custom/custom-script.js" type="text/javascript" th:src="@{/app-assets/js/custom/custom-script.js}"></script>
    <script src="app-assets/js/scripts/admin/activity.js" type="text/javascript" th:src="@{/app-assets/js/scripts/admin/activity.js}"></script>

    <script th:inline="javascript">
    $(".pagination").createPage({
      pageCount: [[${activities.totalPages}]],
      current: [[${activities.number}]] + 1,
      backFn:function(p){
        window.location.href = "activities?page=" + (p - 1) + "&" + $("#search").serialize();
      }
    });

    function search() {
      console.log($("#search").serialize());
      window.location.href = "activities?" + $("#search").serialize();
    }

    function addSubmit() {
    	var input_elems = $('#modal2 .modal-content input, #modal2 .modal-content textarea');
    	input_elems.each(function(){
    		M.validate_field($(this));
   		});
    	var invalid_input_elems = $('#modal2 .modal-content input.invalid, #modal2 .modal-content textarea.invalid');
    	if(invalid_input_elems.length > 0) {
    		var location = $(invalid_input_elems[0]).offset().top - 300;
        document.querySelector('.modal-content').scrollTop = location;
    		return false;
    	}
      $.ajax({
        url: "/kangchenjunga/api/v1/activities/",
        data: '{"title" : "' + $('#modal2 input[name="title"]').val()
            + '", "content" : "' + $('#modal2 textarea[name="content"]').val()
            + '", "company" : {"id" : ' + $('#modal2 select[name="companyId"]').val() + '}'
            + ', "scope" : "' + $('#modal2 input[name="scope"]').val()
            + '", "startDate" : "' + $('#modal2 input[name="startDate"]').val()
            + '", "endDate" : "' + $('#modal2 input[name="endDate"]').val()
            + '", "price" : ' + $('#modal2 input[name="price"]').val()
            + ', "remark" : "' + $('#modal2 input[name="remark"]').val()
            + '"}',
        contentType: "application/json;charset=utf-8",
        type: "POST",
        headers: {
          Accept: "application/json"
        },
        success: function(data, textStatus) {
          console.log(data);
          swal({
            title: "",
            text: "保存成功!",
            icon: "success",
            //timer: 2000,
          });
          window.location.reload();
          $("#modal2 input[type=reset]").trigger("click");
          $('#modal2').modal('close');
        },
        error: function (data, textStatus, errorThrown) {
          //console.log(data);
          swal({
            title: "保存失败!",
            text: data.responseJSON.message,
            icon: "error",
            //timer: 2000,
          });
          M.updateTextFields();
        }
      });

    }

    function openEditModal(activityId) {
      $.ajax({
        url: "/kangchenjunga/api/v1/activities/" + activityId,
        contentType: "application/json;charset=utf-8",
        type: "GET",
        headers: {
          Accept: "application/json"
        },
        success: function(data, textStatus) {
        	$("#modal1 input[type=reset]").trigger("click");
          $('#modal1 input[name="id"]').val(data.id);
          $('#modal1 input[name="title"]').val(data.title);
          $('#modal1 textarea[name="content"]').val(data.content);
          $('#modal1 select[name="companyId"] option').each(function(){
            if($(this).attr('value') == data.company.id) {
            	$(this).attr('selected', 'selected');
            } else {
            	$(this).removeAttr('selected');
            }
          });
          $('#modal1 select[name="companyId"]').formSelect();
          $('#modal1 input[name="scope"]').val(data.scope);
          $('#modal1 input[name="startDate"]').val(data.startDate);
          $('#modal1 input[name="endDate"]').val(data.endDate);
          //$('#modal1 select[name="customerLevels"]').val(data.customerLevels);
          $('#modal1 select[name="customerLevels"] option').each(function(){
           if($(this).attr('value') != '') {
             if(data.customerLevels.includes($(this).attr('value')) > 0) {
                $(this).attr('selected', 'selected');
              } else {
                $(this).removeAttr('selected');
              }
            } else {
             $(this).removeAttr('selected');
            }
          });
          $('#modal1 select[name="customerLevels"]').formSelect();
          $('#modal1 input[name="price"]').val(data.price);
          $('#modal1 input[name="remark"]').val(data.remark);
          M.updateTextFields();
		    	$('#modal1').modal('open');
        }
      });
    }

    function editSubmit() {
    	var input_elems = $('#modal1 .modal-content input, #modal1 .modal-content textarea');
      input_elems.each(function(){
        M.validate_field($(this));
      });
      var startDate = $('#modal1 input[name="startDate"]').val();
      var endDate = $('#modal1 input[name="endDate"]').val();
      var d1 = new Date(startDate.replace(/\-/g, "\/"));
      var d2 = new Date(endDate.replace(/\-/g, "\/"));
      if(startDate != "" && endDate != "" && d1 > d2) {
        $('#modal1 input[name="startDate"]').addClass("invalid");
        $('#modal1 input[name="endDate"]').addClass("invalid");
      }
      var invalid_input_elems = $('#modal1 .modal-content input.invalid, #modal1 .modal-content textarea.invalid');
      if(invalid_input_elems.length > 0) {
    	  var location = $(invalid_input_elems[0]).offset().top - 300;
        document.querySelector('.modal-content').scrollTop = location;
        return false;
      }
      $.ajax({
        url: "/kangchenjunga/api/v1/activities/" + $('#modal1 input[name="id"]').val(),
        data: '{"title" : "' + $('#modal1 input[name="title"]').val() + '"'
        	  + ', "content" : "' + $('#modal1 textarea[name="content"]').val() + '"'
        	  + ', "company" : {"id" : ' + $('#modal1 select[name="companyId"]').val() + '}'
            + ', "scope" : "' + $('#modal1 input[name="scope"]').val() + '"'
            + ', "startDate" : "' + $('#modal1 input[name="startDate"]').val() + '"'
            + ', "endDate" : "' + $('#modal1 input[name="endDate"]').val() + '"'
            + ', "price" : ' + $('#modal1 input[name="price"]').val()
            + ', "remark" : "' + $('#modal1 input[name="remark"]').val() + '"'
            + ', "id" : ' + $('#modal1 input[name="id"]').val()
            + '}',
        contentType: "application/json;charset=utf-8",
        type: "PUT",
        headers: {
          Accept: "application/json"
        },
        success: function(data, textStatus) {
          //console.log(data);
          swal({
            title: "",
            text: "修改成功!",
            icon: "success",
            //timer: 2000,
          });
          window.location.reload();
          //$("#modal2 input[type=reset]").trigger("click");
          $('#modal2').modal('close');
          //$('#modal2').modal();
        },
        error: function (data, textStatus, errorThrown) {
          console.log(data);
          swal({
            title: "保存失败!",
            text: (data.responseJSON.message == '' ? "请联系管理员!" : data.responseJSON.message),
            icon: "error",
            //timer: 2000,
          });
          M.updateTextFields();
        }
      });
    }

    function deleteSubmit(activityId) {
      swal({
        title: "确认删除该条权益吗?",
        text: "一旦删除，将无法找回或查看该条权益!",
        icon: "warning",
        buttons: {
          cancel: {
            text: "取消",
            value: null,
            visible: true,
            className: "waves-effect waves-light btn-flat",
            closeModal: true,
          },
          confirm: {
            text: "确认",
            className: "waves-effect waves-light"
          }
        },
        dangerMode: true,
      })
      .then(function(willDelete) {
        if (willDelete) {
        	console.log(willDelete);
        	$.ajax({
            url: "/kangchenjunga/api/v1/activities/" + activityId,
            contentType: "application/json;charset=utf-8",
            type: "DELETE",
            headers: {
              Accept: "application/json"
            },
            success: function(data, textStatus) {
              //console.log(data);
              swal("删除成功!", {
                icon: "success",
                //timer: 2000,
              });
            	window.location.reload();
            },
            error: function(data) {
            	swal({
                title: "删除失败!",
                text: data.responseJSON.message,
                icon: "error",
              });
            }
          });
        } else {

        }
      });
    }

    function generateSubmit(activityId, amount) {
    	swal({
        title: "确认生成该条权益的优惠券验证码吗?",
        text: "",
        icon: "info",
        buttons: {
          cancel: {
            text: "取消",
            value: null,
            visible: true,
            className: "waves-effect waves-light btn-flat",
            closeModal: true,
          },
          confirm: {
            text: "确认",
            className: "waves-effect waves-light"
          }
        },
        dangerMode: true,
      })
      .then(function(willDelete) {
        if (willDelete) {
          console.log(willDelete);
          $.ajax({
            url: "/kangchenjunga/api/v1/coupons/services/generate/" + activityId + "?amountPerCustomer=" + amount,
            contentType: "application/json;charset=utf-8",
            type: "POST",
            headers: {
              Accept: "application/json"
            },
            success: function(data, textStatus) {
              //console.log(data);
              if(data > 0) {
                swal("生成验证码成功!", {
                  icon: "success",
                  //timer: 2000,
                });
              } else {
                swal("生成验证码失败!", {
                	icon: "error"
                  //timer: 2000,
                });
              }

            }
          });
        } else {

        }
      });
    }

    var p = document.getElementById('checkbox_s');

    function replySubmit(activityId) {
      swal({
        title: "确认回收该条权益吗?",
        text: "",
        icon: "info",
        content: {
          element: p,
        },
        buttons: {
          cancel: {
            text: "取消",
            value: null,
            visible: true,
            className: "waves-effect waves-light btn-flat",
            closeModal: true,
          },
          confirm: {
            text: "确认",
            className: "waves-effect waves-light"
          }
        },
        dangerMode: true,
      })
      .then(function(willDelete) {
        if (willDelete) {
          console.log(willDelete);
          var ignoreCoupons = $("#checkbox_s input").prop("checked");
          console.log(ignoreCoupons);
          $.ajax({
            url: "/kangchenjunga/api/v1/activities/" + activityId + "/interrupt?ignoreCoupons=" + ignoreCoupons,
            contentType: "application/json;charset=utf-8",
            type: "POST",
            headers: {
              Accept: "application/json"
            },
            success: function(data, textStatus) {
              //console.log(data);
              swal("回收成功!", {
                icon: "success",
                //timer: 2000,
              });
              window.location.reload();
            },
            error: function() {
            	swal("回收失败!", {
                icon: "error"
                //timer: 2000,
              });
            }
          });
        } else {

        }
      });
    }

  </script>

  </body>
</html>
